package com;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Test08 {
    public static void main(String[] args) throws IOException {
        Student one = new Student("古力娜扎", 23, "女");
        Student two = new Student("迪丽热巴", 24, "女");
        Student three = new Student("马尔扎哈", 88, "男");

        String path = "HomeWork15\\dir\\学生.txt";

        ArrayList<Student> array = new ArrayList<>();
        array.add(one);
        array.add(two);
        array.add(three);

        BufferedWriter bw = new BufferedWriter(new FileWriter(path));

        for (Student stu : array) {
            StringBuilder sb = new StringBuilder();
            sb.append(stu.getName()).append(",");
            sb.append(stu.getAge()).append(",");
            sb.append(stu.getGender());

            bw.write(sb.toString());
            bw.newLine();
            bw.flush();
        }
        bw.close();
    }
}
